{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Simplify Cerrado cropland ad pasture areas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import numpy as np\n",
    "from tqdm import tqdm\n",
    "import geopandas as gpd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "def simplify_x(x):\n",
    "    try:\n",
    "        return x.simplify(0.0003)\n",
    "    except:\n",
    "        return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 1/1 [28:26<00:00, 1706.02s/it]\n"
     ]
    }
   ],
   "source": [
    "years = (np.arange(1)+2017).astype(np.str) #(np.arange(34)+1985).astype(np.str)\n",
    "\n",
    "for year in tqdm(years):\n",
    "    gdf = gpd.read_file(f'../data/CERRADO/pasture_{year}.shp')\n",
    "    \n",
    "    gdf['geometry'] = gdf['geometry'].apply(lambda x: simplify_x(x)) \n",
    "    \n",
    "    os.makedirs(f'../data/pasture_cerrado/pasture_cerrado_{year}')\n",
    "    \n",
    "    gdf.to_file(f'../data/pasture_cerrado/pasture_cerrado_{year}/pasture_cerrado_{year}.shp')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
